import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2021/12/22
 * \* Time: 11:18
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class TestDemo {
    public static void main(String[] args) {
        ArrayList<String> list2 = new ArrayList<>();
        list2.add("我");
        list2.add("无敌");
        list2.add("存在");
        System.out.println();
        System.out.println("========迭代器List相关打印==========");
        ListIterator<String> it2 = list2.listIterator();
        while (it2.hasNext()) {
            String ret = it2.next();
            if(ret.equals("hello")) {
                it2.remove();//首先需要使用next方法迭代出集合中的元素 ，然后才能调用remove方法
            }else {
                System.out.print(ret + " ");
            }
        }
    }


    public static void main1(String[] args) {
        ArrayList<String> list2 = new ArrayList<>();
        list2.add("我");
        list2.add("无敌");
        list2.add("存在");
        System.out.println(list2);
        System.out.println("================");
        for (int i = 0; i < list2.size(); i++) {
            System.out.print(list2.get(i) + " ");
        }
        System.out.println();
        System.out.println("==================");
        for (String s : list2) {
            System.out.print(s + " ");
        }

        System.out.println();
        System.out.println("========迭代器打印==========");
        Iterator<String> it = list2.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }

        System.out.println();
        System.out.println("========迭代器List相关打印==========");
        ListIterator<String> it2 = list2.listIterator();
        while (it2.hasNext()) {
            System.out.print(it2.next() + " ");
        }
    }
}
